<!DOCTYPE html>
<html>
  <head>
    <title>Drag-and-drop test</title>
    <style>
      #drop {
        width: 5em;
        height: 5em;
        border: 1px solid black;
      }
    </style>
  </head>
  <body>
    <div id="drag" draggable="true">drag me</div>
    <div id="drop"></div>
    <script>
      window.didDragStart = false;
      window.didDragEnter = false;
      window.didDragOver = false;
      window.didDrop = false;
      var drag = document.getElementById('drag');
      var drop = document.getElementById('drop');
      drag.addEventListener('dragstart', function(e) {
        e.dataTransfer.setData('id', e.target.id);
        window.didDragStart = true;
      });
      drop.addEventListener('dragenter', function(e) {
        e.preventDefault();
        window.didDragEnter = true;
      });
      drop.addEventListener('dragover', function(e) {
        e.preventDefault();
        window.didDragOver = true;
      });
      drop.addEventListener('drop', function(e) {
        e.preventDefault();
        var id = e.dataTransfer.getData('id');
        var el = document.getElementById(id);
        if (el) {
          e.target.appendChild(el);
          window.didDrop = true;
        }
      });
    </script>
  </body>
</html>
